//
//  SlideTopViewTwo.m
//  庐山通
//
//  Created by zcj on 15-10-30.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "SlideTopViewTwo.h"
#import "TopSlideCell.h"
#import "GoodDataFrame.h"
#import <UIKit/UIKit.h>
#import "Grouble.h"

@interface SlideTopViewTwo()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,weak)UICollectionView *collectionView;

@property (nonatomic,strong)NSMutableArray * modelData;
@property (nonatomic,strong) UIPageControl * pageControl;
@end
@implementation SlideTopViewTwo

- (NSMutableArray *)modelData
{
    if (_modelData == nil) {
        _modelData = [[NSMutableArray alloc]init];
    }
    return _modelData;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addCollecion];
        [self setUpPage];
        // Initialization code
    }
    return self;
}
- (void)setUpPage
{
    _pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(ScreenWidth/2-20, self.height - 30 + 5, 0, 20)];
    _pageControl.currentPage = 0;
    _pageControl.numberOfPages = 2;
    _pageControl.currentPageIndicatorTintColor = ZCJColor(39, 38, 54);
    _pageControl.pageIndicatorTintColor = [UIColor whiteColor];
    //[self addSubview:_pageControl];
    

    
}
- (void)setUrlStr:(NSString *)urlStr
{
    _urlStr = urlStr;
    [self.modelData addObject:urlStr];
    [self.collectionView reloadData];
}

- (void)addCollecion
{
     UICollectionViewFlowLayout *flow=[[UICollectionViewFlowLayout alloc]init];
    flow.itemSize=self.frame.size;
    
    UICollectionView *collectionView=[[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:flow];
    
    [collectionView registerClass:[TopSlideCell  class] forCellWithReuseIdentifier:@"topslide"];
    
    collectionView.delegate=self;
    collectionView.dataSource=self;
    [self addSubview:collectionView];
    
    self.collectionView =collectionView;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.modelData.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TopSlideCell * cell = [TopSlideCell TopSlideCell:collectionView collectionIndex:indexPath];
    ZCJLog(@"cellForItemAtIndexPath");
    cell.imageUrl = self.modelData[indexPath.row];
    return cell;
}
@end
